/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: XMQ
 * Date: 2022-05-28
 * Time: 14:27
 */

import java.sql.SQLOutput;
import java.util.Arrays;

/**
 * String
 * java里面的字符串没有所谓的/0结尾
 *
 */
class Student{
    public int age;

    public Student(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age='" + age + '\'' +
                '}';
    }
}
public class TestDemo {
    
    public static void main21(String[] args) {
        String s1 = "hello";
        s1 = "test";
        System.out.println(s1);
    }
    public static void main20(String[] args) {
        String s1 = "hello";
        String s2 = s1 + " word";
        System.out.println(s2);
    }
    public static void main19(String[] args) {
        final char[] ch = new char[]{'a','b','c'};
        ch[0] = 'p';
        System.out.println(ch);
    }
    public static void main18(String[] args) {
        char[] ch = {'a','b','c'};
        String s1 = new String(ch);
        s1.intern();//手动入池
        String s2 = "abc";
        System.out.println(s1 == s2);
    }
    public static void main17(String[] args) {
        String s1 = "hello";
        String s2 = "hello";
        System.out.println(s1 == s2);
        String s3 = new String("hello");
        System.out.println(s1 == s3);
    }
    public static void main16(String[] args) {
        String s1 = "     liu yu     ";
        System.out.println(s1);
        System.out.println(s1.trim());
    }
    public static void main15(String[] args) {
        String s1 = "liuyuhao";
        System.out.println(s1.substring(3));
        System.out.println(s1.substring(2, 5));//[2,5)左闭右开
    }
    public static void main14(String[] args) {
        //多次拆分
        String s1 = "zaiganma nihao&=nibuhao";
        String[] s2 = s1.split(" ");
        for (String x : s2) {
            String[] s3 = x.split("=");
            for (String x1 : s3) {
                System.out.println(x1);
            }
        }
    }
    public static void main13(String[] args) {
        String s1 = "zaiganma nihao&=nibuhao";
        String[] s2 = s1.split(" |=");
        for (String x : s2) {

            System.out.println(x);
        }
    }
    public static void main12(String[] args) {
        String s1 = "255\\255\\255\\255";
        //特殊的字符要进行转义
        String[] s2 = s1.split("\\\\");
        for (String x : s2) {
            System.out.println(x);
        }
    }
    public static void main11(String[] args) {
        String s1 = "255.255.255.255";
        //特殊的字符要进行转义
        String[] s2 = s1.split("\\.");
        for (String x : s2) {
            System.out.println(x);
        }
    }
    public static void main10(String[] args) {
        String s1 = "ni hao ma zui jin";
        String[] s2 = s1.split(" ",3);
        for (String x : s2) {
            System.out.println(x);
        }
    }
    public static void main9(String[] args) {
        String s1 = "ababcabcdeaaweqggh";
        System.out.println(s1);
        System.out.println(s1.replace('a', 'k'));
        System.out.println(s1.replace("ab", "wt"));
        System.out.println(s1.replaceAll("ab","zc"));
        System.out.println(s1.replaceFirst("ab","1122"));
    }
    public static void main8(String[] args) {
        //字符串变数组
        String s1 = "hello";
        String s2 = "123";
        char[] ch = s1.toCharArray();
        for (char x : ch) {
            System.out.println(x);
        }
    }
    public static void main7(String[] args) {
        String s1 = "hello";
        String s2 = "HELLO";
        System.out.println(s1.toUpperCase());
        System.out.println(s2.toLowerCase());
        System.out.println(s1);
        System.out.println(s2);
    }
    public static void main6(String[] args) {
        //字符串转换
        String s1 = String.valueOf(123);
        String s2 = String.valueOf(12.5);
        System.out.println(s1);
        System.out.println(s2);

        String s3 = String.valueOf(new Student(12));
        System.out.println(s3);

        int a = Integer.valueOf("0101",2);
        System.out.println(a);
        int b = Integer.parseInt("1000");
        System.out.println(b);
    }
    public static void main5(String[] args) {
        String s1 = "ababacabcdaseasq";
        String s2 ="www.baidu.com";
        System.out.println(s2.lastIndexOf('.',4));
        System.out.println(s2.lastIndexOf('.'));
        System.out.println(s1.lastIndexOf('a'));
    }
    public static void main4(String[] args) {
        String s1 = "hello";
        for (int i = 0; i < s1.length(); i++) {
            System.out.println(s1.charAt(i));
        }
        System.out.println("====================");
        System.out.println(s1.indexOf('h'));//查找第一次出现的字符
        System.out.println(s1.indexOf('l',3));
        System.out.println("====================");
        String s2 = "abaabcabcdabsaea";
        System.out.println(s2.indexOf("abcd"));
    }
    public static void main3(String[] args) {
        String s1 = "hello";
        String s2 = "HELLO";
        //忽略大小写进行比较相同
        System.out.println(s1.equals(s2));
        System.out.println(s1.equalsIgnoreCase(s2));
        //忽略大小写进行比较是否大小
        System.out.println(s1.compareTo(s2));
        System.out.println(s1.compareToIgnoreCase(s2));
    }
    public static void main2(String[] args) {
        String s1 = new String("hello");
        String s2 = new String("hello");
        String s3 = new String("word");

        System.out.println(s1 == s2);
        System.out.println(s1.equals(s2));

        System.out.println(s1 == s3);
        System.out.println(s1.equals(s3));

        System.out.println(s1.compareTo(s2));
    }
    public static void main1(String[] args) {
        String s1 = "hello";
        String s2 = new String("qwer");
        char[] ch = new char[]{'a','b','c'};
        String s3 = new String(ch);

        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);

        System.out.println(s1.length());
        int[] arr = {1,2,3};
        System.out.println(arr.length);
        System.out.println("nihaoma".length());
    }
}
